package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BaseBlacklistIpsMapper;
import com.ruoyi.system.domain.BaseBlacklistIps;
import com.ruoyi.system.service.IBaseBlacklistIpsService;

/**
 * 黑名单Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-13
 */
@Service
public class BaseBlacklistIpsServiceImpl implements IBaseBlacklistIpsService {
    @Autowired
    private BaseBlacklistIpsMapper baseBlacklistIpsMapper;

    /**
     * 查询黑名单
     *
     * @param id 黑名单主键
     * @return 黑名单
     */
    @Override
    public BaseBlacklistIps selectBaseBlacklistIpsById(Long id) {
        return baseBlacklistIpsMapper.selectBaseBlacklistIpsById(id);
    }

    /**
     * 查询黑名单列表
     *
     * @param baseBlacklistIps 黑名单
     * @return 黑名单
     */
    @Override
    public List<BaseBlacklistIps> selectBaseBlacklistIpsList(BaseBlacklistIps baseBlacklistIps) {
        return baseBlacklistIpsMapper.selectBaseBlacklistIpsList(baseBlacklistIps);
    }

    /**
     * 新增黑名单
     *
     * @param baseBlacklistIps 黑名单
     * @return 结果
     */
    @Override
    public int insertBaseBlacklistIps(BaseBlacklistIps baseBlacklistIps) {
        baseBlacklistIps.setCreateTime(DateUtils.getNowDate());
        return baseBlacklistIpsMapper.insertBaseBlacklistIps(baseBlacklistIps);
    }

    /**
     * 修改黑名单
     *
     * @param baseBlacklistIps 黑名单
     * @return 结果
     */
    @Override
    public int updateBaseBlacklistIps(BaseBlacklistIps baseBlacklistIps) {
        baseBlacklistIps.setUpdateTime(DateUtils.getNowDate());
        return baseBlacklistIpsMapper.updateBaseBlacklistIps(baseBlacklistIps);
    }

    /**
     * 批量删除黑名单
     *
     * @param ids 需要删除的黑名单主键
     * @return 结果
     */
    @Override
    public int deleteBaseBlacklistIpsByIds(Long[] ids) {
        return baseBlacklistIpsMapper.deleteBaseBlacklistIpsByIds(ids);
    }

    /**
     * 删除黑名单信息
     *
     * @param id 黑名单主键
     * @return 结果
     */
    @Override
    public int deleteBaseBlacklistIpsById(Long id) {
        return baseBlacklistIpsMapper.deleteBaseBlacklistIpsById(id);
    }

    @Override
    public Boolean findByIp(String addressip) {
        BaseBlacklistIps info = new BaseBlacklistIps();
        info.setAddressIp(addressip);
        List<BaseBlacklistIps> list = baseBlacklistIpsMapper.selectBaseBlacklistIpsList(info);
        return list.size() > 0 ? true : false;
    }
}
